/**********************************************************************
*   Copyright: (C)2021 LingYun IoT System Studio <www.weike-iot.com>
*      Author: GuoWenxue<guowenxue@gmail.com> QQ: 281143292
* Description: BearKE1 NB-IoT Board OLED display test source code
*
*      Notice: Must implement delay_us() by timer in tim.h first.
*
*   ChangeLog:
*        Version    Date       Author            Description
*        V1.0.0  2021.08.10  GuoWenxue      Release initial version
***********************************************************************/
#include <stdio.h>
#include "oled.h"
#include "hal_oled.h"
#include "font_bmp.h"
#include "font_hzk.h"

/*
 *+-------------------------------------------------+
 *|            OLED Board display API               |
 *+-------------------------------------------------+
 */ 

void OLED_ShowBanner(int showtime)
{
	uint8_t          i;
	uint8_t          pos_x = 25;
	uint8_t          pos_y = 0;	
	
	OLED_Clear();
	OLED_DrawBMP(0,0,128,7, &LOGO_BMP[0][0]);
	HAL_Delay(showtime);

	OLED_Clear();

	for(i=0; i<HZK_LEN_LINGYUN; i++)
		OLED_ShowChinese(Hzk_LingYun, pos_x+i*16, pos_y, i);

	pos_x = 5;
	pos_y = 2;
	OLED_ShowString(pos_x, pos_y, "Hello, LingYun!", OLED_FONT16);

	HAL_Delay(showtime);
}


void OLED_ShowTempHumdity(uint32_t temp, uint32_t humd, int showtime)
{
	uint8_t          i;
	char             temp_str[10] = {0}; /* Tempearute  : 28.32'C */
	char             humd_str[16] = {0}; /* Humidity    : 58.39%  */
	uint8_t          pos_x = 5;
	uint8_t          pos_y = 0;
	
	snprintf(temp_str, sizeof(temp_str), ": %02d.%02d\'C", (int)temp/100, (int)temp%100);
	snprintf(humd_str, sizeof(humd_str), ": %02d.%02d%%",  (int)humd/100, (int)humd%100);
	
	OLED_Clear();
	
	for(i=0; i<2*HZK_LEN_TEMP; i++)
		OLED_ShowChinese(Hzk_Temp, pos_x+i*16, pos_y, i);
	
	pos_x += 16*HZK_LEN_TEMP;
	OLED_ShowString(pos_x, pos_y, temp_str, OLED_FONT16);
	
	pos_x = 5;
	pos_y = 2;
	
	for(i=0; i<HZK_LEN_HUMD; i++)
		OLED_ShowChinese(Hzk_Humd, pos_x+i*16, pos_y, i);	
	
	pos_x += 16*HZK_LEN_HUMD;
	OLED_ShowString(pos_x, pos_y, humd_str, OLED_FONT16);	
	
	HAL_Delay(showtime);	
}

void OLED_ShowLightNoisy(uint32_t light, uint32_t noisy, int showtime)
{
	uint8_t          i;
	char             light_str[10] = {0}; 
	char             noisy_str[16] = {0}; 
	uint8_t          pos_x = 5;
	uint8_t          pos_y = 0;
	
	snprintf(light_str, sizeof(light_str), ": %04d", (int)light);
	snprintf(noisy_str, sizeof(noisy_str), ": %04d", (int)noisy);
	
	OLED_Clear();
	
	for(i=0; i<2*HZK_LEN_LIGHT; i++)
		OLED_ShowChinese(Hzk_Light, pos_x+i*16, pos_y, i);
	
	pos_x += 16*HZK_LEN_LIGHT;
	OLED_ShowString(pos_x, pos_y, light_str, OLED_FONT16);
	
	pos_x = 5;
	pos_y = 2;
	
	for(i=0; i<HZK_LEN_NOISY; i++)
		OLED_ShowChinese(Hzk_Noisy, pos_x+i*16, pos_y, i);	
	
	pos_x += 16*HZK_LEN_NOISY;
	OLED_ShowString(pos_x, pos_y, noisy_str, OLED_FONT16);	
	
	HAL_Delay(showtime);	
}
